package com.wyp.springbootinit.manager;

import com.qiniu.common.QiniuException;
import com.qiniu.http.Response;
import com.qiniu.storage.Configuration;
import com.qiniu.storage.Region;
import com.qiniu.storage.UploadManager;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.File;

/**
 * @author 4413
 */
@Component
public class KodoManager {

    @Resource
    private String upToken;

    public Response uploadFile(String key, File file) throws QiniuException {
        Configuration cfg = new Configuration(Region.huabei());
        cfg.resumableUploadAPIVersion = Configuration.ResumableUploadAPIVersion.V2;
        UploadManager uploadManager = new UploadManager(cfg);
        return uploadManager.put(file, key, upToken);
    }
}
